const propString = (rec, propSpec) => {

  if (!propSpec.includes('.')) {

    return rec[propSpec];

  } else {

    const path = propSpec.split('.').reverse();

    let curr = rec;
    while(curr && path.length > 0) {
      curr = curr?.[path.pop()];
    }
    return curr;

  }
}

export const prop = (rec, propSpec='') => {

  if (typeof propSpec === 'function') {

    return propSpec(rec);

  } else if (Array.isArray(propSpec)) {

    return Object.fromEntries(propSpec.map(propSpec => [propSpec, prop(rec, propSpec)]));

  } else {

    return propString(rec, propSpec);

  }
}